﻿using Project.Ycm20250401.Service._20250418.Domain.Entities;
using Project.Ycm20250401.Service._20250418.Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project.Ycm20250401.Service._20250418.Application
{
    public class UserBankService
    {
        private readonly IUserBankRepository _userBankRepository;

        public UserBankService(IUserBankRepository userBankRepository)
        {
            _userBankRepository = userBankRepository;
        }
        /// <summary>
        /// 绑定银行卡
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="bankCardNo"></param>
        /// <param name="bankCardHolder"></param>
        /// <param name="bankName"></param>
        /// <returns></returns>
        public async Task<bool> BindBankCard(string userId, string bankCardNo, string bankCardHolder, string bankName)
        {
           var userBank=await _userBankRepository.GetUserBankByUserId(userId);
            userBank.BindBankItem(new BankItem(Guid.NewGuid().ToString(),bankCardNo, bankCardHolder, bankName));
            await _userBankRepository.SaveUserBank(userBank);
            return true;
        }
        /// <summary>
        /// 解绑银行卡
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="bankCardId"></param>
        /// <returns></returns>
        public async Task<bool> UnbindBankCard(string userId, string bankCardId)
        {
            var userBank = await _userBankRepository.GetUserBankByUserId(userId);
            userBank.UnBindBankItem(bankCardId);
            await _userBankRepository.SaveUserBank(userBank);
            return true;
        }
    }
}
